﻿using System;
using System.Reflection;

namespace FactoryApp
{
    class Program
    {
        static void Main(string[] args)
        {
            String type = System.Configuration.ConfigurationManager.AppSettings["type"];//类型会经常变. 放到配置文件中 java:config.property

            //反射：根据字符串的路径，生产对应的类对象。
            //1.程序集
            //2.类的全名/全路径（namespace.classname）
            IFactory f = null;
            f = Assembly.Load("FactoryApp").CreateInstance(type) as IFactory;

            //if (type == "File")
            //{
            //    f = new FileFactory(); //"FactoryApp.FileFactory"
            //}
            //else if (type == "Database")
            //{
            //    f = new DatabaseFactory(); //"FactoryApp.DatabaseFactory"
            //}

            ILogger logger = f.CreateLogger();
            logger.WriteLog("this is a test");
        }
    }
}
